import React, { useState, useEffect } from 'react'
import { View } from '@tarojs/components'
import Taro, { useDidShow, useShareAppMessage,useShareTimeline, useDidHide } from '@tarojs/taro'
import Swiper from './swiper/index'
import Nav from './nav/index'
import Banner from './banner/index'
import Tab from './tab/index'
import api from '../../http/api'
import ToLogin from '../../compontents/toLogin'


// import "taro-ui/dist/style/components/tab-bar.scss";

import './index.less'


export default (props: any) => {
  const [data, setData] = useState({ "id": 1, "srcs": "https://static.zhongningwenhua.com/uniSchool/upload/72de9170e46b048cf2a4f4bddfbe649f.png&https://static.zhongningwenhua.com/uniSchool/upload/ebe3852a65761f0eddc989bacd9c475b.png", "src": "https://static.zhongningwenhua.com/uniSchool/upload/d285fe537dc2deb8597e74f454afce9d.png" })
  const info: any = Taro.getStorageSync('info')
  const uSchoolId = info ? JSON.parse(info).userInfo.uSchoolId : 0
  useDidShow(() => {
    api.version().then((res:any)=>{
      const version = res.data
      if(version === 1){
        api.indexInfo({uSchoolId}).then((res: any) => {
          setData(res.data)
        })
      }
    })
  })
  useShareAppMessage(res => {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: 'U你校园',
      path: '/pages/index/index'
    }
  })
  useShareTimeline(()=>{
    return{
			title:'U你校园',
      path: '/pages/index/index',
			query:'' 	
		}
  })

  const handleChange = () => { }
  return (
    <View className='wrap'>
      <ToLogin url='/pages/index/index'></ToLogin>
      <View>
        <Banner data={data} />
        <Nav />
        <Swiper data={data} />
        <Tab />
      </View>
    </View>
  );
};
